<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //https://www.baidu.com/home/weather/getweather?citycode=3675&bsToken=c03c19059f58a0e4c76af756402e0012&indextype=manht&_req_seqid=0xe365a4210000d65a&asyn=1&t=1683777468241&sid=38516_36555_38529_38470_38538_38468_38594_38598_38486_38414_26350_22160_38542

        var baidu = '{"data":{"timeStamp":1683792894,"fetchTimeStamp":1683791259,"updateTimeStamp":1683790920,"provinceName":"北京","cityName":"北京","countyName":"北京","linkSeven":"http://www.weather.com.cn/weather/101010100.shtml#7d","currentWeather":"阴","currentWeatherIcon":"a2","currentTemp":"26","currentAqiValue":"90","currentAqiLevel":"良","weatherArr":[{"date":"05月11日","time":"周四","dateInfo":{"date":"5月11日","lunar":"三月廿二","timeStamp":1683734400,"festival":"","weatherSourceUrl":""},"temp":"13 ~ 27","wind":"南风\u003c3级","condition":"小雨","imgs":["a7","a7"],"link":"http://www.weather.com.cn/weather/101010100.shtml#7d","pm25":"90","pm25url":"//www.baidu.com/s?wd=北京空气质量指数\u0026amp;tn=baidutop10\u0026amp;rsv_idx=2"},{"date":"05月12日","time":"周五","dateInfo":{"date":"5月12日","lunar":"三月廿三","timeStamp":1683820800,"festival":"","weatherSourceUrl":""},"temp":"15 ~ 28","wind":"西风\u003c3级","condition":"多云","imgs":["a1","a1"],"link":"http://www.weather.com.cn/weather/101010100.shtml#7d","pm25":"","pm25url":"//www.baidu.com/s?wd=北京空气质量指数\u0026amp;tn=baidutop10\u0026amp;rsv_idx=2"},{"date":"05月13日","time":"周六","dateInfo":{"date":"5月13日","lunar":"三月廿四","timeStamp":1683907200,"festival":"","weatherSourceUrl":""},"temp":"16 ~ 28","wind":"南风\u003c3级","condition":"多云","imgs":["a1","a1"],"link":"http://www.weather.com.cn/weather/101010100.shtml#7d","pm25":"","pm25url":"//www.baidu.com/s?wd=北京空气质量指数\u0026amp;tn=baidutop10\u0026amp;rsv_idx=2"},{"date":"05月14日","time":"周日","dateInfo":{"date":"5月14日","lunar":"三月廿五","timeStamp":1683993600,"festival":"母亲节","weatherSourceUrl":""},"temp":"17 ~ 30","wind":"南风\u003c3级","condition":"晴","imgs":["a0","a0"],"link":"http://www.weather.com.cn/weather/101010100.shtml#7d","pm25":"","pm25url":"//www.baidu.com/s?wd=北京空气质量指数\u0026amp;tn=baidutop10\u0026amp;rsv_idx=2"},{"date":"05月15日","time":"周一","dateInfo":{"date":"5月15日","lunar":"三月廿六","timeStamp":1684080000,"festival":"","weatherSourceUrl":""},"temp":"20 ~ 33","wind":"南风3-4级","condition":"晴转多云","imgs":["a0","a1"],"link":"http://www.weather.com.cn/weather/101010100.shtml#7d","pm25":"","pm25url":"//www.baidu.com/s?wd=北京空气质量指数\u0026amp;tn=baidutop10\u0026amp;rsv_idx=2"}],"weatherType":"aladdin","pslink":"//www.baidu.com/s?tn=baidutop10\u0026rsv_idx=2\u0026wd=北京天气预报","pollution":"10","alarm":[{"type":"雷电","level":"黄色","color":"fcc419"}]},"errno":0,"msg":"ok"}';
        //结果: [{date:'',temp:'',wind:'',condition:'',pm25:''},{date:'',temp:'',wind:'',condition:'',pm25:''},{},{},{}]
        // json 转成 js数据类型 
        // 使用json格式化工具 方便分析数据结构 
        // 看看想要的数据在哪里  一层层的找 
        // 主要是对象 就根据键取值 
        // 数组需要遍历 或者根据下标取值 
        var target = JSON.parse(baidu);
        // console.log(typeof target)// target 是个对象 
        //先找到第一层 
        // console.log(target['data']);
        // 再找第二层 
        // console.log(target['data']['weatherArr']);// 是个数组

        // 上面是个数组 就可以把数组遍历一下  
        var res = [];
        for(var v of target['data']['weatherArr']){
            // console.log(v)  v是数组中一个个的对象
            //
            //提取v中的内容放到1个新的对象中 
            
            // 从原数据中提取数据放到新对象中 
            // 所有的对象放到数组中 
            var obj = {}; // 每次循环准备一个新的对象 
            obj['date'] = v['date']; //date是新的键 值从v中提取
            obj['time'] =  v['time'];
            obj['temp'] =  v['temp'];
            obj['wind'] =  v['wind'];
            obj['condition'] =  v['condition'];
            obj['pm25'] =  v['pm25'];
            res.push(obj);





        }

        console.log(res); // 最后这就是我们想要的结果
    </script>
</body>
</html>